header {

/**
 *
 * @Author: Marek Zakowicz <mazak (at) debian (dot) linux.org.pl>
 *
 * Copyright (c) 2005, 2006, 2007 Marek Zakowicz. All rights reserved.
 *
 * Licence: This code may be used, (re)distribute and/or modify under the terms one of the following two kinds of licence:
 *          1) as free software under GPL 3 (General Public Licence ver. 3 as published by the Free Software Foundation)
 *          2) as software under the terms individual licence from Marek Zakowicz
 *
 *          This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *          without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package jsp2php;
import java.io.*;

}

class JSPParser extends Parser;

options {
   k=1;
}

{
   private StringBuilder temp = new StringBuilder(1024); // Zbiera kolejne fragmenty (atomy - poziom 2 parsera) przynalezne do tej samej grupy

   Java2PHPConverter converter=new Java2PHPConverter();
}

// SYNDIAGSTART

// Level 0 (TOP)
file throws Exception : ( ( jsp_code | jsp_expr | text )+ | EOF) ;

// Level 1
jsp_code throws Exception : LTAG (chars|less|percent)* RTAG    { converter.processCode( temp.toString() ); temp.setLength(0); } ;
jsp_expr throws Exception : EXPRTAG (chars|less|percent)+ RTAG { converter.processExpr( temp.toString() ); temp.setLength(0); } ;
text                      : (chars|less|percent|rtag)          { converter.processText( temp.toString() ); temp.setLength(0); } ;

// SYNDIAGSTOP

// Level 2 (BOTTOM)
chars                 : t: CHAR { temp.append(t.getText());  }  ;
less                  : LESS    { temp.append("<"); } ;
percent               : PERCENT { temp.append("%"); } ;
rtag                  : RTAG    { temp.append("%>"); } ;

class JSPLexer extends Lexer;

options {
   k=3;
   charVocabulary = '\0'..'\377';
   //charVocabulary = '\3'..'\377' | '\u1000'..'\u1fff';
   //testLiterals = false;
}

CHAR    : ~('<'|'%');
LESS    : '<';
PERCENT : '%';
LTAG    : '<' '%';
EXPRTAG : '<' '%' '=';
RTAG    : '%' '>';
